﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CommonLibrary.Common;
using System.IO;

namespace OAclient.Common
{
    public class FileHelper
    {
        #region tree_node_helper
        
        /// <summary>
        /// 获取给定目录文件下的所有文件返回ztreeNode
        /// </summary>
        /// <param name="file_path">"c:\program"</param>
        /// <returns></returns>
        public static Node GetFileTree(string file_path, string rootNode_name)
        {
            Node tree = new Node(rootNode_name, "0", false, false);
            GetFile(file_path, tree);
            return tree;
        }


        private static void GetFile(string filepath, Node node)
        {
            DirectoryInfo di = new DirectoryInfo(filepath);
            node.Tag = di.FullName;
            if (!di.Exists) return;
            foreach (FileInfo file in di.GetFiles("*"))
            {
                node.Nodes.Add(new Node()
                {
                    Text = file.Name,
                    Value = "0",
                    Tag = file.FullName,
                    Expand = false,
                    ShowCheckBox = false,
                });
            }
            foreach (DirectoryInfo dir in di.GetDirectories("*"))
            {
                Node childNode = new Node()
                {
                    Text = dir.Name,
                    Value = "0",
                    Tag = dir.FullName,
                    Expand = false,
                    ShowCheckBox = false,
                };
                node.Nodes.Add(childNode);
                GetFile(dir.FullName, childNode);
            }
        }

        #endregion

    }
}
